import { Router } from 'vue-router'
import { start, done } from '@/libs/nprogress'

/**
 * 注册路由钩子函数
 *
 * @param router 路由实例
 * @returns 返回路由实例
 */
export default function registerHook(router: Router): Router {
  router.beforeEach((to, from, next) => {
    start()
    next()
  })

  router.afterEach(() => {
    done()
  })

  router.onError((error) => {
    console.log('路由错误：', error)
  })

  return router
}
